package com.alogic.swagger.core;

import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.plugins.Segment;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * Info
 *
 * @since 1.6.13.7 [20200812 duanyy] <br>
 */
public class SwaggerInfo extends Segment {
    private String $title;
    private String $desc;
    private String $term;
    private String $version;

    public SwaggerInfo(String tag, Logiclet p) {
        super(tag, p);
    }

    @Override
    public void configure(Properties p){
        super.configure(p);

        $title = PropertiesConstants.getRaw(p,"title","");
        $desc = PropertiesConstants.getRaw(p,"description","");
        $term = PropertiesConstants.getRaw(p,"term","");
        $version = PropertiesConstants.getRaw(p,"version","");
    }

    @Override
    protected void onExecute(XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
        XsObject newCurrent = current.getObjectChild("info",true);

        newCurrent.addProperty("title",PropertiesConstants.transform(ctx,$title,""));
        newCurrent.addProperty("description",PropertiesConstants.transform(ctx,$desc,""));
        newCurrent.addProperty("term",PropertiesConstants.transform(ctx,$term,""));
        newCurrent.addProperty("version",PropertiesConstants.transform(ctx,$version,""));

        super.onExecute(root,newCurrent,ctx,watcher);
    }
}
